﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net.Configuration;
using System.Collections.Generic;
using DataAccess.DataObject;
namespace EnmineKaitlin
{
    public partial class popupsendmail : Common.PageBase
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["p"] != null && Request["p"].ToString() != "")
            { 
                
            }           
        }
        protected void btnSend_Click(object sender, EventArgs e)
        {
            if (Request["p"] != null && Request["p"].ToString() != "")
            {
                IList<OPost> lstPost = _BPost.Get(int.Parse(Request["p"].ToString()));
                if (lstPost.Count > 0)
                {
                    string content = "<table border='0'>";
                    content += "<tr><td>Gửi từ:</td><td>" + txtName.Text + "(" + txtYourMail.Text + ")</td></tr>";
                    content += "<tr><td>Tiêu đề:</td><td>" + txtTitle.Text + "</td></tr>";
                    content += "<tr><td>Nội dung:</td><td></td></tr>";
                    content += "<tr><td colspan='2'>" + txtContent.Text + "</td></tr>";
                    content += "<tr><td colspan='2'><h3>" + lstPost[0].Title + "</h3></td></tr>";
                    content += "<tr><td colspan='2'>" + lstPost[0].Content + "</td></tr>";
                    content += "</table>";
                    string subject = "[send-mail-EnmineKaitlin]-" + txtTitle.Text;
                    SmtpSection cfg = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
                    List<string> lstSendTo = new List<string>();
                    lstSendTo.Add(txtSendMail.Text.Trim());
                    if (Send_Email(cfg.Network.UserName, lstSendTo, subject, content))
                    {
                        RegisterClientScriptBlock("NOTE", "<script>alert(" + ConfigurationManager.AppSettings["send_mail_success"].ToString() + ");</script>");
                    }
                    else
                    {
                        RegisterClientScriptBlock("NOTE", "<script>alert(" + ConfigurationManager.AppSettings["send_mail_fail"].ToString() + ");</script>");
                    }
                }
            }
        }
    }
}
